#include<bits/stdc++.h>
using namespace std;

class Solution
{
private:
    /* data */
public:
    int maxSubarraySumCircular(vector<int>& nums){
        int len=nums.size();
        if(len<2){
            return nums[0];
        }
        int max_sum,max_res=INT_MIN;
        int min_sum,min_res=INT_MAX;
        max_sum=max_res=min_sum=min_res=nums[0];
        int total=nums[0];
        for(int i=1;i<len;++i){
            max_sum=max(max_sum+nums[i],nums[i]);
            min_sum=min(min_sum+nums[i],nums[i]);
            max_res=max(max_sum,max_res);
            min_res=min(min_sum,min_res);
            // cout<<min_res;
            total=total+nums[i];
        }
        // 全负数
        if(max_res<0){
            return max_res;
        }
        cout<<total<<endl;
        return max(max_res,total-min_res);
    }
};

int main(int argc, char const *argv[])
{
    vector<int> nums={5,-3,5};
    Solution s;
    int res = s.maxSubarraySumCircular(nums);
    cout<<res<<endl;
    return 0;
}


